package com.liuyk.commonlib.widget.navigation;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Checkable;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

/**
 * 导航条子item
 * <p>
 * Created by liuyakui on 2020/2/5.
 */
public abstract class BaseBottomNavigationItem<T> extends LinearLayout implements Checkable {
    private boolean isCheck;

    public BaseBottomNavigationItem(Context context) {
        this(context, null);
    }

    public BaseBottomNavigationItem(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BaseBottomNavigationItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        final View view = LayoutInflater.from(getContext()).inflate(bottomNavigationItemResId(), this, false);
        addView(view);
        onCreate();
    }

    protected abstract void onCreate();

    public abstract int bottomNavigationItemResId();

    public abstract void renderItemView(int index, T t);

    @Override
    public void setChecked(boolean checked) {
        isCheck = checked;
    }

    @Override
    public boolean isChecked() {
        return isCheck;
    }

    @Override
    public void toggle() {
        isCheck = !isCheck;
    }
}
